package com.ybxx.asset.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.dao.StructuresDao;
import com.ybxx.asset.model.Building;
import com.ybxx.asset.model.Structures;
import com.ybxx.asset.service.StructuresService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;

public class StructuresServiceImpl extends BaseServiceImpl<Structures>
		implements StructuresService {
	private StructuresDao structuresDao;
	public StructuresServiceImpl(StructuresDao dao) {
		super(dao);
		this.structuresDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<Structures> queryPage(Structures structures, QueryFilter filter) {
		String hql="from Structures s where 1=1 ";
		if(structures!=null && StringUtils.isNotEmpty(structures.getZcbh())){
			hql+=" and s.zcbh like '%"+structures.getZcbh()+"%'";
		}
		if(structures!=null && StringUtils.isNotEmpty(structures.getSname())){
			hql+=" and s.sname like '%"+structures.getSname()+"%'";
		}
		if(structures!=null && StringUtils.isNotEmpty(structures.getMdept())){
			hql+=" and s.mdept like '%"+structures.getMdept()+"%'";
		}
		
		return structuresDao.findByHql(hql, null, filter.getPagingBean());
	}
	public List<Structures> exportExcel_Print(Structures structures) {
		String hql="from Structures s left join fetch s.company c where 1=1 ";
		if(structures!=null && StringUtils.isNotEmpty(structures.getZcbh())){
			hql+=" and s.zcbh like '%"+structures.getZcbh()+"%'";
		}
		if(structures!=null && StringUtils.isNotEmpty(structures.getSname())){
			hql+=" and s.sname like '%"+structures.getSname()+"%'";
		}
		if(structures!=null && StringUtils.isNotEmpty(structures.getMdept())){
			hql+=" and s.mdept like '%"+structures.getMdept()+"%'";
		}
		
		return structuresDao.findByHql(hql, null);
	}
	@Override
	public Structures get(String id) {
		String hql="from Structures s left join fetch s.company c where sid='"+id+"' ";
		return (Structures)structuresDao.findUnique(hql, null);
	}
}
